| Author | Manuela Ruiz (mruiz@lcc.uma.es) |
This class represents a linked list used for the pi permutation of CurrentLabelledShape
| returns | an identical PiList object to this |
# File lib/data-structures.rb, line 375
375: def clone()
376: new_lllist = PiList.new
377: current = @first
378: while current
379: new_node = current.clone
380: new_lllist.insert_node(new_node)
381: current = current._next
382: end
383: return new_lllist
384: end
| returns | returns, in each invocation, the next node, in order, in the list |
# File lib/data-structures.rb, line 357
357: def get_next()
358: if @current_node == Constants::START
359: @current_node = @first
360: elsif @current_node
361: @current_node = @current_node._next
362: else
363: self.reset_iterator
364: end
365: result = @current_node
366: return result
367: end
i::index ofthe node to be retrieved
| returns | the node in the position i, or nil if i >= size of the list |
# File lib/data-structures.rb, line 344
344: def get_node_i(i)
345: if (i < @size)
346: j = 0
347: result = @first
348: while (j < i)
349: result = result._next
350: j += 1
351: end
352: end
353: return result
354: end
| n | LinearLinkedListNode to add |
Inserts the node, maintaining the order of the list. Doesn’t matter if keys are repeated
# File lib/data-structures.rb, line 311
311: def insert_node(n)
312: previous = nil
313: current = @first
314: found = false
315: while (current && !found)
316: if (n.key < current.key)
317: found = true
318: elsif (n.key == current.key)
319: found = true
320: else
321: previous = current
322: current = current._next
323: end
324: end
325:
326: if !previous #Is the first node
327: n._next = @first
328: @first = n
329: @current_node = Constants::START
330: else # General case (or last to be added if !found)
331: previous._next = n
332: n._next = current
333: end
334:
335: @size += 1
336: result = n
337:
338: return result
339: end
resets the iterator used by get_next()
# File lib/data-structures.rb, line 370
370: def reset_iterator()
371: @current_node = Constants::START
372: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.